layui.use(['table', 'layer'], function () {
    var table = layui.table;
    var layer = layui.layer;

    /**
     * 物联卡综合信息-物联卡已订购资费
     */
    var GeneralOrderedCharges = {
        tableId: "generalOrderedChargesTable",    //表格id
        condition: {
            msisdn: ""
        }
    };

    /**
     * 初始化表格的列
     */
    GeneralOrderedCharges.initColumn = function () {
        return [[
            {field: 'number', align: "center", title: '序号',type:'numbers',width: 60},
            {field: 'offeringId', align: "center", title: '资费ID'},
            {field: 'offeringName', align: "center", title: '资费名称'},
            {field: 'effectiveDate', align: "center", title: '生效时间'},
            {field: 'expiriedDate', align: "center", title: '失效时间'},
            {field: 'apnName', align: "center", title: 'APN'},
            {align: 'center', toolbar: '#menuChangeCharges', title: '可变更资费'}
        ]];
    };

    // 渲染表格
    table.render({
        elem: '#' + GeneralOrderedCharges.tableId,
        url: Feng.ctxPath + '/general/orderedCharges?accountId='+ $("#accountId").val() + '&cardType=' + $("#cardType").val()+ '&cardNum=' + $("#cardNum").val(),
        height: "full-98",
        page: false,
        cellMinWidth: 100,
        cols: GeneralOrderedCharges.initColumn()
    });

    //工具条点击事件
    table.on('tool(' + GeneralOrderedCharges.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'menuChangeCharges') {
            GeneralOrderedCharges.searchMenuChangeCharges(data);
        }
    });

    /**
     * 查看物联卡可变更资费信息
     *
     * @param data 点击按钮时候的行数据
     */
    GeneralOrderedCharges.searchMenuChangeCharges = function (data) {
        layer.open({
            type: 2,
            title: '物联卡可变更资费',
            area: ['850px', '540px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/general/changeable_charges/' + $("#accountId").val() + '/' +  $("#cardType").val() + '/' + $("#cardNum").val() + '/'+  data.offeringId,
            btn: ['关闭']
        });
    };
});